<?php
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 * auth wangliangfeng 2014/6/14
 */
class Uuch_RestController extends Zend_Rest_Controller {
    
    protected $cdn = "http://cdn.uuch.com";
    
    public function __construct(\Zend_Controller_Request_Abstract $request, \Zend_Controller_Response_Abstract $response, array $invokeArgs = array()) {
        header('Access-Control-Allow-Origin:*');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
        parent::__construct($request, $response, $invokeArgs);
    }

    public function indexAction() {
        
    }
    
    public function getAction() {
        return false;
    }
    
    public function postAction() {
        return false;
    }
    
    public function putAction() {
        return false;
    }
    
    public function deleteAction() {
        return false;
    }
    /**
     * @return 检索传入参数是否符合规范
     */
    protected function analysisParams($params) {
//        var_dump($params);exit;
        if($params["functionName"] != "UserLogin") { 
            if(!array_key_exists("head", $params)) {
                return array("Result"=>1003,"ResultMessage"=>"head.auth的值未设置。");
            }
        }
        if(!array_key_exists("functionName", $params)) {
            return array("Result"=>1002,"ResultMessage"=>"传入参数错误-方法名没有传入。");
        }
        if(!method_exists($this,$params["functionName"])){
            return array("Result"=>1006,"ResultMessage"=>"所需要的服务不存在或者暂不可用");
        }
        return array("Result" => 1);
    }
    
    protected function analysisLogin($params) {
        if(!array_key_exists("functionName", $params)) {
            return array("Result"=>1002,"ResultMessage"=>"传入参数错误-方法名没有传入。");
        }
        if(!method_exists($this,$params["functionName"])){
            return array("Result"=>1006,"ResultMessage"=>"所需要的服务不存在或者暂不可用");
        }
        return array("Result" => 1);
    }




    protected function analysisAuth($paramHead) {
        if(!array_key_exists("auth", $paramHead) || $paramHead["auth"] == "") {
            return array("Result"=>1003,"ResultMessage"=>"head.auth的值未设置。");
        }
        $auth = Uuch_Util::decryptString($paramHead["auth"]);
        $authItem = explode("&", $auth);
        if((strtotime($authItem[1])+(100*60))<  strtotime("now")) {
            return array("Result"=>1005,"ResultMessage"=>"head.auth传入的ticket过期。");
        }
        return array("Result"=>1,"userId"=>$authItem[0]);
    }    
}